const fileReader = require('./fileReader')

let files = fileReader.read('actions/')

let actions = {}

for (let file of files) {
    if (file.name.endsWith('.js')) {
        let method = file.name.substring(0, file.name.length - 3)
        actions['/' + method] = require('./' + file.path)
    }
}

function route (pathname) {
    let method = actions[pathname]

    if (method) {
        console.log('Route: ' + pathname + ' Resolved.')
    }

    return method
}

exports.route = route
